from models import AppEXCD,AppBase
from nodes.app import AppNodeCD
from flow import make_flow

def get_globlas():
    return globals()

def create_app(flow,appcode):
    if flow=='FlowCD':
        AppNodeCD.create(appcode,flow)
    elif flow=='FlowNJ':
        AppNodeCD.create(appcode,flow)
    return {'status':'success'}

def get_flows():
    out=[]
    for app in AppBase.objects.all():
        fl = make_flow(app)
        if fl:
            out.append( fl.get_show() )
        
    return {'flows':out}

def add_version(appcode,vercode):
    app=AppBase.objects.get(appcode=appcode)
    fl=make_flow(app)
    fl.add_version(vercode)

def add_qa(appcode,vercode):
    app=AppBase.objects.get(appcode=appcode)
    fl=make_flow(app)
    fl.add_qa(vercode)

def add_rel_qa(appcode,vercode):
    app=AppBase.objects.get(appcode=appcode)
    fl=make_flow(app)
    fl.add_rel_qa(vercode)    
    
def add_sub(appcode,vercode):
    app=AppBase.objects.get(appcode=appcode)
    fl=make_flow(app)
    fl.add_sub(vercode)